/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package shoppingClient;

import java.util.HashMap;
import java.util.Random;

/**
 *
 * @author MinhDuc
 */
public class ShoppingClientModel {
    private int id;
    private HashMap<String, Product> shoppingCart;

    public ShoppingClientModel() {
        Random random = new Random() ;
        id = random.nextInt(10000);
       
        shoppingCart = new HashMap<String,Product>();
    }

    protected int getID() {
        return id;
    }

    protected boolean contain(String name) {
        return shoppingCart.containsKey(name);
    }

    protected void addItem(String name) {
        shoppingCart.get(name).inc();
        System.out.println("addItem");
    }

    protected void addProduct(String name, Product product) {
        shoppingCart.put(name, product);
        shoppingCart.get(name).inc();
        System.out.println("addProduct");
    }

   protected  void removeItem(String name) {
       shoppingCart.get(name).dec();
        
        if(shoppingCart.get(name).getAmount()==0){
            shoppingCart.remove(name);
        }
        System.out.println("size after remove: "+ shoppingCart.size());
    }
    
    protected HashMap<String, Product> getBuyList(){
        return shoppingCart;
    }

    protected void reset() {
        shoppingCart = new HashMap<String,Product>();
        System.out.println("ok reset");
    }
}
